<template>
  <div class="login-container">
  <div style="position:relative;top:23%">
  <div class="title-container">
        <h3 class="title"><img src="../../assets/images/poplogo.png" style="margin-top:16px;"/></h3>
      </div>
    <el-form class="login-form" autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left">
<!--       <div class="title-container">
        <h3 class="title"><img src="../../assets/images/poplogo.png" style="margin-top:16px;"/></h3>
      </div> -->
      <div>
      <el-form-item prop="account">
        <span class="svg-container svg-container_login">
          <svg-icon icon-class="user" />
        </span>
        <el-input name="username" type="text" v-model="loginForm.account" :maxlength="20" autoComplete="on" placeholder="用户名" />
      </el-form-item>
      <el-form-item prop="psd">
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>
        <el-input name="password" :type="passwordType" @keyup.enter.native="handleLogin" v-model="loginForm.psd" :minlength="6" :maxlength="20" autoComplete="on" placeholder="密码" />
        <!-- <span class="show-pwd" @click="showPwd">
          <svg-icon icon-class="eye" />
        </span> -->
      </el-form-item>
      <el-button type="primary" style="width:100%;margin-bottom:30px;height:40px;margin-top:20px;font-size:18px;font-weight:400;" :loading="loading" @click.native.prevent="handleLogin">登 录</el-button>
      </div>
    </el-form
>    </div>
  </div>
</template>

<script>

import { isvalidUsername } from '@/utils/validate'
import * as api from '@/api/login'

export default {
  data() {
    return {
      loginForm: {
        account: '',
        psd: '',
        userName: ''
      },
      loginRules: {
        account: [{ required: true, message: '账号不能为空', trigger: 'blur'}],
        psd: [{ required: true, message: '密码不能为空', trigger: 'blur'}]
      },
      passwordType: 'password',
      loading: false
    }
  },
  methods: {
    showMessage(type,message){
      this.$message({
        type: type,
        message: message
      });
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          var that = this
          this.$store.dispatch('LoginByUsername', this.loginForm).then(res => {
            this.$store.dispatch('myUnreadMessage')
            this.$store.dispatch('GetMenu').then(() => {
              this.$store.dispatch('GetBtn', function() {
                that.$router.push({ path: '/index' })
              }).then((res) => {
              })
            })
            this.loading = false
          }).catch(err => {
            // if(+err.code === 103){
            //   this.$message({
            //     message: '用户名或密码错误',
            //     type: 'error',
            //     showClose: true
            //   })
            // }
            this.loading = false
          })
        }
      })
    }

    // handleLogin() {
    //   this.$refs.loginForm.validate(valid => {
    //     if (valid) {
    //       api.loginByUsername({
    //           account: this.loginForm.account,
    //           psd: this.loginForm.psd
    //       })
    //       this.loading = true
    //       this.$store.dispatch('LoginByUsername', this.loginForm).then(() => {
    //         this.loading = false
    //         this.$router.push({ path: '/index' })
    //       }).catch(() => {
    //         this.loading = false
    //       })
    //     } else {
    //       console.log('error submit!!')
    //       return false
    //     }
    //   })
    // }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
$bg:#fff;
$light_gray:#505050;

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 40px;
    width: 87%;
    input {
      background: #fff!important;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: #454545 !important;
      }
    }
  }
  .el-form-item {
    background: #fff;
    border-radius: 5px;
    height:40px;
    color: #454545;
    margin-bottom:20px;
  }
}
.login-container .el-input input:focus{border-style:solid;border-color: #03a9f4;box-shadow: 0 0 15px #03a9f4;}
.el-input--medium .el-input__inner{height:38px;}
.login-container .el-input input{padding:0!important;}
</style>

<style rel="stylesheet/scss" lang="scss" scoped>
$bg:#2d3032;
$dark_gray:#454545;
$light_gray:#fff;

.login-container {
  background:url(../../assets/images/bg-login.png) top center no-repeat;
  position: fixed;
  height: 100%;
  width: 100%;
  background-color: $bg;
  .login-form {
    position: absolute;
    left: 0;
    right: 0;
    width: 450px;
    height:258px;
    background:url(../../assets/images/loginbg.png) top center no-repeat;
    padding: 35px 35px 15px 35px;
    margin: auto;
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
  .svg-container {
    padding: 3px 7px 3px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    margin-right:8px;
    display:inline-block;
    &_login {
      font-size: 20px;
    }
  }
  .title-container {
    height:110px;
    position: relative;
    .title {
      font-size: 26px;
      font-weight: 400;
      color: $light_gray;
      margin: 0px auto 80px auto;
      text-align: center;
      font-weight: bold;
    }
    .set-language {
      color: #fff;
      position: absolute;
      top: 5px;
      right: 0px;
    }
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
  .thirdparty-button {
    position: absolute;
    right: 35px;
    bottom: 28px;
  }
}
</style>
